<?php

namespace app\api\controller;

use helper\JwtHandler;
use traits\controller\JumpTraits;
use traits\controller\ListTraits;

class BaseController
{

  use JumpTraits;
  use ListTraits;

  /**
   * Request实例
   * @var \think\Request
   */
  protected $request;

  /**
   * 应用实例
   * @var \think\App
   */
  protected $app;


  public function __construct()
  {
    $this->app       = app();
    $this->request   = $this->app->request;
  }

  /**
   * 校验签名
   * @return bool|string
   */
  protected function checkToken()
  {
    try {
      $token = $this->request->param('token');
      $info = JwtHandler::encode($token,config('cloud.tencent.secretKey'));
      if(empty($info)) abort('令牌校验错误');
    } catch (\Exception $e){
      return false;
    }
    return $info;
  }

}